var element = layui.element, form = layui.form;//导航的hover效果、二级菜单等功能，需要依赖element模块
var tagsInput = layui.tagsInput;
$("i[tooltip]").each(function () {
    var t = $(this).attr('tooltip');
    $(this).tooltip({
        text: t
    });
});

//监听导航点击
element.on('nav(demo)', function (elem) {
    //console.log(elem)
    var navdata = $(elem[0]).attr("data-nav");
    $(".setting").hide();
    $("#" + navdata).css("display", "flex");
});
$("#zhanghao").css("display", "flex");
form.on('select(receivetype)', function (data) {
    var message = $("select[name=receivetype]").val();
    if (message == "4") {
        $("#imapxs").show();
    } else {
        $("#imapxs").hide();
    }
});


//监听提交 ....
form.on('submit(form-element-zhanghao1)', function (data) {

});

form.on('checkbox(qyyc)', function (data) {
    if (data.elem.checked) {
        $('#yc').attr("disabled", false);
    } else {
        $("#yc").attr("disabled", true);
        $("#yc").val("");
    }
});
form.on('checkbox(qybc)', function (data) {
    if (data.elem.checked) {
        $('#bc').attr("disabled", false);
    } else {
        $("#bc").attr("disabled", true);
        $("#bc").val("");
    }
});
form.on('select(mrzt)', function (data) {
    $(".weizi span").css("font-family", data.value)
});
form.on('select(ztdx)', function (data) {
    $(".weizi span").css("font-size", data.value)
});

$('.scli').on('click', function () {
    var parent = $(this).parent();
    $(parent).remove();
});

function tjhmd(types) {
    $("input[name='tjhmd']").val("");
    layer.open({
        type: 1
        , title: types == "blacklistlent" ? "添加邮件地址" : "添加主题过滤字"
        , area: ['420px', '160px']
        , btn: ['确定', '取消']
        , skin: 'layui-layer-rim' //加上边框
        , content: $("#tjhmddiv")
        , yes: function (index, layero) {
            var value = $("input[name='tjhmd']").val();
            if (value != "") {
                var na = "";
                if (types == "blacklistlent") {
                    na = "blackEmail"
                }
                if (types == "blacklistr") {
                    na = "blackSubject"
                }
                var newli = '<li><input name="' + na + '" value="' + value + '"><span class="caozuo scli"><i class="layui-icon">&#xe640;</i></span></li>'
                $("." + types + " ul").append(newli);
            }
            $('.scli').on('click', function () {
                var parent = $(this).parent();
                $(parent).remove();
            });
            layer.close(index);
        }
        , btn2: function (index, layero) {
            //按钮【按钮二】的回调
            //return false 开启该代码可禁止点击该按钮关闭
        }
    });
}

//事件
var active = {
    tjzh: function () {
        layer.open({
            type: 1
            , title: "添加账号"
            , area: ['420px', '240px']
            , btn: ['确定', '取消']
            , skin: 'layui-layer-rim' //加上边框
            , content: $("#tjzhfrom")
            , yes: function (index, layero) {

                var name = $("input[name='email']").val();
                var pass = $("input[name='pass']").val();
                //新建账号
                $.ajax({
                    url: 'email/insertPopAndSmtp',
                    type: 'GET',
                    contentType: "application/json; charset=utf-8",
                    data: {
                        "name": name,
                        "pass": pass
                    },
                    success: function (date) {
                        layer.msg(date.data)
                        location.reload();　//layer.open关闭刷新
                    }
                });
                //按钮【按钮一】的回调
                layer.close();
            }
            , btn2: function (index, layero) {
                //按钮【按钮二】的回调
                //return false 开启该代码可禁止点击该按钮关闭
            }
        });
    },
    scli: function (data) {
        layer.msg(kg)
    },
    shojiana2: function () {
        $("#form-elementdiv2").hide();
        $("#editor-form2").show();
    }
};
$('.shijian').on('click', function () {
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
});

function searchs() {
    layer.open({
        type: 2
        , title: "选择联系人"
        , area: $(window).width() < 458 ? "['100%', '100%']" : ['75%', '75%']
        , shade: 0.8
        , btn: ['确定', '取消']
        , btnAlign: 'c'
        , moveType: 1 //拖拽模式，0或者1
        , content: 'views/jsp/BasicData/email/searchs.jsp'
        , yes: function (index, layero) {
            //按钮【按钮一】的回调
        }
        , btn2: function (index, layero) {
            //按钮【按钮二】的回调

            //return false 开启该代码可禁止点击该按钮关闭
        }
    });
}

form.on('select(sptj)', function (data) {
    if (data.value != "全部审批") {
        $("#spnrdiv").css("display", "flex");
    } else {
        $("#spnrdiv").hide();
    }
});

layui.use(['dropdown', 'colorpicker', 'tagsInput'], function () {
    var dropdown = layui.dropdown, colorpicker = layui.colorpicker;
    //表单赋值
    colorpicker.render({
        elem: '#test-form'
        , done: function (color) {
            $('#test-form-input').val(color);
            $(".weizi span").css("color", color)
        }
    });
    $('#spr').tagsInput({//审批
        // skin: 'tagsinput-default',
        autocomplete_url: 'email/selectDimEmailAddress',
        removeWithBackspace: true

    });
    $('#syxgzzh').tagsInput({
        // skin: 'tagsinput-default',
        autocomplete_url: 'email/selectDimEmailAddress',
        removeWithBackspace: true

    });
    $('#defaultCopy').tagsInput({
        // skin: 'tagsinput-default',
        autocomplete_url: 'email/selectDimEmailAddress',
        removeWithBackspace: true

    });
    $('#defaultDark').tagsInput({
        // skin: 'tagsinput-default',
        autocomplete_url: 'email/selectDimEmailAddress',
        removeWithBackspace: true
    });
    $('#forceCopy').tagsInput({
        // skin: 'tagsinput-default',
        autocomplete_url: 'email/selectDimEmailAddress',
        removeWithBackspace: true

    });
    $('#forceDark').tagsInput({
        // skin: 'tagsinput-default',
        autocomplete_url: 'email/selectDimEmailAddress',
        removeWithBackspace: true

    });
    $('#rule_context').tagsInput({
        // skin: 'tagsinput-default',
        autocomplete_url: 'email/selectDimEmailAddress',
        removeWithBackspace: true

    });

    // 监听菜单点击
    dropdown.onFilter('more', function (event) {
        console.log(event)
        // ...业务代码
    })


});
var Emailaccouts = "";
$(document).ready(function () {
    showAccounts();
    showTemplateName()
    setdeploy()
    showEmailRules()
    showUserBox()
});

function showAccounts() {
    $.ajax({
        url: 'email/showAccount',
        type: 'GET',
        async: false, // 同步
        success: function (date) {
            var accounts = date.data;
            Emailaccouts = accounts;
            for (let i in accounts) {
                var statues = "";
                if (accounts[i].acccountStatue == 1) {
                    statues = "（启用中）"
                } else if (accounts[i].acccountStatue == 0) {
                    statues = "（禁用中）"
                } else if (accounts[i].acccountStatue == 2) {
                    statues = "（默认）"
                }
                $("#accounts").append("<li><span><i class=\"layui-icon\">&#xe671;</i><a href=\"javascript:void(0);\" onclick='showAccount(" + accounts[i].account_id + ")'>" +statues + accounts[i].account_name +  "</a></span>\n" +
                    "<span class=\"caozuo\"><i class=\"layui-icon\" tooltip=\"默认\" onclick='setMo(" + accounts[i].account_id + ")'>&#xe605;</i><i class=\"layui-icon\" tooltip=\"启用\" onclick='setTrue(" + accounts[i].account_id + ")'>&#xe673;</i><i class=\"layui-icon\" tooltip=\"删除\" onclick='setno(" + accounts[i].account_id + ")'>&#xe640;</i></span></li>")
            }
        }
    });
}

function showAccount(accid) {//展示邮箱账户数据
    var popid = "";
    var smtpid = "";
    for (let i in Emailaccouts) {
        if (Emailaccouts[i].account_id == accid) {
            popid = Emailaccouts[i].pop3_id;
            smtpid = Emailaccouts[i].smtp_id;
        }
    }
    //获取pop
    $.ajax({
        url: 'email/selectPop3ById',
        type: 'GET',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: {
            "popid": popid
        },
        success: function (date) {
            var pop3 = date.data;
            $("#pop3_id").val(pop3.pop3_id);
            $("#pop3_name").val(pop3.pop3_name);
            $("#popemail_adress").val(pop3.email_adress);
            $("#pop3_server").val(pop3.pop3_server);
            $("#popemail_name").val(pop3.email_name);
            $("#popemail_password").val(pop3.email_password);
            $("#popemail_code").val(pop3.email_code);
            $("#pop3_port").val(pop3.pop3_port);
            if(pop3.pop_email_num!=null&&pop3.pop_email_num!=""){
                $("#pop_email_num").val(pop3.pop_email_num);
            }
        }
    });
    //获取smtp
    $.ajax({
        url: 'email/selectSmtpById',
        type: 'GET',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: {
            "smtpid": smtpid
        },
        success: function (date) {
            var smtp = date.data;
            $("#smtp_id").val(smtp.smtp_id)
            $("#smtpName").val(smtp.smtp_name)
            $("#smtpsend_name").val(smtp.send_name)
            $("#smtpemail_adress").val(smtp.email_adress);
            $("#smtpbank_adress").val(smtp.bank_adress);
            $("#smtp_server").val(smtp.smtp_server);
            $("#smtpemail_name").val(smtp.email_name);
            $("#smtpemail_password").val(smtp.email_password);
            $("#smtpemail_code").val(smtp.email_code);
            $("#smtp_port").val(smtp.smtp_port);
        }
    });
}

function setMo(accid) {//设置邮箱默认
    $.ajax({
        url: 'email/changeAccountStatue',
        type: 'GET',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: {
            "accid": accid,
            "statues": 2
        },
        success: function (date) {
            layer.msg(date.data)
            $("#accounts").find("li").empty();
            showAccounts();
            location.reload();　//layer.open关闭刷新
        }
    });


}

function setTrue(accid) {//启用邮箱
    $.ajax({
        url: 'email/changeAccountStatue',
        type: 'GET',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: {
            "accid": accid,
            "statues": 1
        },
        success: function (date) {
            layer.msg(date.data)
            $("#accounts").find("li").empty();
            showAccounts();
            location.reload();　//layer.open关闭刷新
        }
    });

}

function setno(accid) {//删除邮箱
    layer.open({
        type: 1
        , title: "是否确认删除"
        , btn: ['确定', '取消']
        , yes: function (index, layero) {
            $.ajax({
                url: 'email/deleteAccount',
                type: 'GET',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: {
                    "accid": accid,
                },
                success: function (date) {
                    layer.msg(date.data)
                    $("#accounts").find("li").empty();
                    showAccounts();
                    location.reload();　//layer.open关闭刷新
                }
            });
        }
        , btn2: function (index, layero) {
            layer.close();

            //return false 开启该代码可禁止点击该按钮关闭
        }
    });


}

//
// function deleteacc(accid) {//删除邮箱账户
//     var popid = "";
//     var smtpid = "";
//     for (let i in Emailaccouts) {
//         if (Emailaccouts[i].account_id == accid) {
//             popid = Emailaccouts[i].pop3_id;
//             smtpid = Emailaccouts[i].smtp_id;
//         }
//     }
//     $.ajax({
//         url: 'email/deleteAccount',
//         type: 'GET',
//         contentType: "application/json; charset=utf-8",
//         dataType: "json",
//         data: {
//             "accid": accid,
//             "pop3id": popid,
//             "smtpid": smtpid
//         },
//         success: function (date) {
//             $("#accounts").find("li").empty();
//             showAccounts();
//         }
//
//     });
//     $("#accounts").find("li").empty();
//     showAccounts();
// }


function getSmtp() {
    var smtp = {
        "smtp_id": $("#smtp_id").val(),
        "smtp_user_id": -1,
        "smtp_name": $("#smtpName").val(),
        "send_name": $("#smtpsend_name").val(),
        "email_adress": $("#smtpemail_adress").val(),
        "bank_adress": $("#smtpbank_adress").val(),
        "smtp_server": $("#smtp_server").val(),
        "email_name": $("#smtpemail_name").val(),
        "email_password": $("#smtpemail_password").val(),
        "email_code": $("#smtpemail_code").val(),
        "smtp_port": $("#smtp_port").val(),
        "smtp_useStatus": 0
    }
    return smtp;
}

function smtpLinkTest() {
    var smtp = getSmtp();
    $.ajax({
        url: 'email/smtpLinkTest',
        type: 'POST',
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify(smtp),
        success: function (date) {
            if (date.data != "") {
                layer.msg(date.data + "----未通过连接测试无法进行保存")
            } else {
                layer.msg("发送连接成功，已保存")
            }
        }
    });
}

function getPop() {
    var email_num=$("#pop_email_num").val()
    if(email_num==""){
        email_num=-1
    }
    var pop3 = {
        "pop3_id": $("#pop3_id").val(),
        "pop3_user_id": -1,
        "pop3_name": $("#pop3_name").val(),
        "send_name": 0,
        "email_adress": $("#popemail_adress").val(),
        "pop3_class": "imap",
        "pop3_server": $("#pop3_server").val(),
        "email_name": $("#popemail_name").val(),
        "email_password": $("#popemail_password").val(),
        "email_code": $("#popemail_code").val(),
        "pop3_port": $("#pop3_port").val(),
        "pop_email_num":email_num,
        "pop3_useStatus": 0,
        "pop_getTime": $('input:radio[name="pt"]:checked').val(),
    }
    return pop3;
}

function popLinkTest() {
    var pop3 = getPop();
    $.ajax({
        url: 'email/popLinkTest',
        type: 'POST',
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify(pop3),
        success: function (date) {
            if (date.data != "") {
                layer.msg(date.data + "----未通过连接测试无法进行保存")
            } else {
                layer.msg("接收连接成功，已保存")
            }
        }
    });
}

function getDate() {
    var val = CKEDITOR.instances.textarea.getData();
    return val;
}

var tems = "";
var temid = -1;

//保存签名
function saveTemplate() {

    var date1 = getDate();
    $.ajax({
        url: 'email/saveTemplate',
        type: 'GET',
        contentType: "application/json; charset=utf-8",
        data: {
            "temid": temid,
            "TemplateName": $("#templateName").val(),
            "TemplateText": date1
        },
        success: function (date) {
            $("#templateName").val("");
            CKEDITOR.instances.textarea.setData("");
            layer.msg(date.data)
            showTemplateName()
        }
    });
}

//展示签名
function showTemplateName() {
    $("#template").find("li").remove()
    $.ajax({
        url: 'email/showTemplate?type=1',
        type: 'Get',
        success: function (date) {
            tems = date.data;
            for (let i in tems) {
                if (tems[i].templateStatue == 1) {
                    $("#template").append("<li><span><a href='javascript:void(0)' onclick='showTemplateOne(" + tems[i].template_id + ")'>" + tems[i].template_name + "(默认)</a></span><span class=\"caozuo\"><i class=\"layui-icon\" onclick='setdefaultTemplate(" + tems[i].template_id + ")' tooltip=\"默认\">&#xe605;</i><i class=\"layui-icon\" onclick='deleteTemplate(" + tems[i].template_id + ")' tooltip=\"删除\">&#xe640;</i></span></li>")
                } else {
                    $("#template").append("<li><span><a href='javascript:void(0)' onclick='showTemplateOne(" + tems[i].template_id + ")'>" + tems[i].template_name + "</a></span><span class=\"caozuo\"><i class=\"layui-icon\" onclick='setdefaultTemplate(" + tems[i].template_id + ")' tooltip=\"默认\">&#xe605;</i><i class=\"layui-icon\" onclick='deleteTemplate(" + tems[i].template_id + ")' tooltip=\"删除\">&#xe640;</i></span></li>")
                }
            }
        }
    });
}

function showTemplateOne(id) {
    var tem = "";
    for (let i in tems) {
        if (tems[i].template_id == id) {
            tem = tems[i]
            temid = id
        }
    }
    $("#templateName").val(tem.template_name)
    setDate(tem.template_text);
}

function addTemRemove() {
    temid = -1;
    $("#templateName").val("")
    setDate("");
}

function setDate(ht) {
    CKEDITOR.instances.textarea.setData(ht);
}

function setdefaultTemplate(tid) {
    $.ajax({
        url: 'email/setdefaultTemplate',
        type: 'GET',
        contentType: "application/json; charset=utf-8",
        data: {
            "tid": tid
        },
        success: function (date) {
            layer.msg("设置成功")
            showTemplateName()
        }
    });
}

function deleteTemplate(tid) {
    $.ajax({
        url: 'email/deleteTemplate',
        type: 'GET',
        contentType: "application/json; charset=utf-8",
        data: {
            "tid": tid
        },
        success: function (date) {
            layer.msg(date.data)
            showTemplateName()
        }
    });
}


//设置保存或修改
function savedeploy() {
     var deploy = getdeploy()
    $.ajax({
        url: 'email/savedeploy',
        type: 'POST',
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify(deploy),
        success: function (date) {
            layer.msg("保存成功");
        }
    });

}

//填入设置
function setdeploy() {
    $.ajax({
        url: 'email/showdeploy',
        type: 'GET',
        success: function (date) {

            var deploy = date.data;
            if (deploy.deploy_id != null) {
                if (deploy.momStart != null) {
                    $("#momStart").val(deploy.momStart)
                }
                if (deploy.momEnd != null) {
                    $("#momEnd").val(deploy.momEnd)
                }
                if (deploy.delaySend != null) {
                    $("#yc").val(deploy.delaySend)
                }
                if (deploy.autoSave != null) {
                    $("#bc").val(deploy.autoSave)
                }
                if (deploy.display != null) {
                    $("input[name='xsms'][value=" + deploy.display + "]").attr("checked", true);
                }
                if (deploy.timeZone != null) {
                    $("#timeZone").find("option[value='" + deploy.timeZone + "']").attr("selected", true);
                }
                if (deploy.font != null) {
                    $("#font").find("option[value='" + deploy.font + "']").attr("selected", true);
                }
                if (deploy.fontSize != null) {
                    $("#fontSize").find("option[value='" + deploy.fontSize + "']").attr("selected", true);
                }
                if (deploy.fontColor != null) {
                    $("#test-form-input").val(deploy.fontColor)
                }
                if (deploy.defaultCopy != null) {
                    $('#defaultCopy').importTags(deploy.defaultCopy);
                }
                if (deploy.defaultDark != null) {
                    $('#defaultDark').importTags(deploy.defaultDark);
                }
                if (deploy.forceCopy != null) {
                    $('#forceCopy').importTags(deploy.forceCopy);
                }
                if (deploy.forceDark != null) {
                    $('#forceDark').importTags(deploy.forceDark);
                }
                if (deploy.blackEmail != null) {
                    var blackEmail = deploy.blackEmail
                    var be = blackEmail.split("&&");
                    for (let i in be) {
                        if (be[i] != "") {
                            $("#blackEmail").append('<li><input name="blackEmail" value="' + be[i] + '"><span class="caozuo scli"><i class="layui-icon">&#xe640;</i></span></li>')
                        }
                    }

                }
                if (deploy.blackSubject != null) {
                    var blackSubject = deploy.blackSubject
                    var bs = blackSubject.split("&&")
                    for (let i in bs) {
                        if (bs[i] != "") {

                            $("#blackSubject").append('<li><input name="blackSubject" value="' + bs[i] + '"><span class="caozuo scli"><i class="layui-icon">&#xe640;</i></span></li>')
                        }

                    }
                }
            }
            form.render();

        }
    });
}

function  setCopyAndDark(elem,value) {
    console.log(elem,value)

    $(elem).tagsInput('add', value);
}

//取得设置
function getdeploy() {

    var copy = $("#defaultCopy").val();
    var dark = $("#defaultDark").val();
    var fcopy = $("#forceCopy").val()
    var fdark = $("#forceDark").val()
    var blackEmail = "";
    $("input[name='blackEmail']").each(function (j, item) {
        if (item != "") {
            blackEmail += item.value + "&&"
        }

    });
    if (blackEmail == "&&") {
        blackEmail = "";
    }
    var blackSubject = "";
    $("input[name='blackSubject']").each(function (j, item) {
        if (item != "") {
            blackSubject += item.value + "&&"
        }

    });
    if (blackSubject == "&&") {
        blackSubject = "";
    }
    var deploy = {
        "deploy_id": -1,
        "deploy_user": -1,
        "momStart": $("#momStart").val(),
        "momEnd": $("#momEnd").val(),
        "delaySend": $("#yc").val(),
        "autoSave": $("#bc").val(),
        "display": $("input[name='xsms']:checked").val(),
        "timeZone": $('#timeZone option:selected').val(),
        "font": $('#font option:selected').val(),
        "fontSize": $('#fontSize option:selected').val(),
        "fontColor": $("#test-form-input").val(),
        "defaultCopy": copy,
        "defaultDark": dark,
        "forceCopy": fcopy,
        "forceDark": fdark,
        "blackEmail": blackEmail,
        "blackSubject": blackSubject
    }
    return deploy
}

var EmailRules = "";

//左侧展示所有的收信规则
function showEmailRules() {
    $.ajax({
        url: 'email/showEmailRules',
        type: 'GET',
        success: function (date) {
            EmailRules = date.data
            for (let i in EmailRules) {
                var nn=''
                if(EmailRules[i].rule_context!=null&&EmailRules[i].rule_context!=''){
                    nn=EmailRules[i].rule_context
                }else{
                    nn=EmailRules[i].rule_name
                }
                $("#EmailRules").append("<li><span><a href='javascript:void(0)' onclick='showRule(" + EmailRules[i].rule_id + ")'>" +"收信:"+nn+ "</span><span class=\"caozuo\"><i onclick='deleteRule(" + EmailRules[i].rule_id + ")' class=\"layui-icon\" tooltip=\"删除\">&#xe640;</i></span></li>")
            }
        }
    });
}

var rulesid = -1;

function newAddRule() {
    rulesid = -1;
    $("#rule_name").val("")
    $("#rule_context").val("")
}

//右侧显示单个收信规则
function showRule(id) {
    var rule = null;
    for (let i in EmailRules) {
        if (EmailRules[i].rule_id == id) {
            rule = EmailRules[i]
            rulesid = EmailRules[i].rule_id
        }
    }
    $("#rule_name").val(rule.rule_name)
    $("#userBox").find("option[value='" + rule.box_id + "']").attr("selected", true);
    $("#rule_context").importTags(rule.rule_context)
    form.render();
}

//展示所有用户的箱子
function showUserBox() {
    $.ajax({
        url: 'email/selectBox',
        type: 'GET',
        success: function (date) {
            var boxs = date.data
            for (let i in boxs) {
                if(boxs[i].box_grade==1){
                    $("#userBox").append("<option value=\"" + boxs[i].box_id + "\">" + boxs[i].box_name + "</option>")
                }
            }
            for (let i in boxs) {
                if(boxs[i].box_grade==0){
                    $("#userBox").append("<option value=\"" + boxs[i].box_id + "\">" + boxs[i].box_name + "</option>")
                }
            }
            form.render();
        }
    });
}
function changeBox() {
    var dim=$("#sqzwb").val()
    $("#userBox").find("option").remove()
    $.ajax({
        url: 'email/selectBox',
        type: 'GET',
        success: function (date) {
            var boxs = date.data
            for (let i in boxs) {
                if(boxs[i].box_name.indexOf(dim)!=-1){
                    $("#userBox").append("<option value=\"" + boxs[i].box_id + "\">" + boxs[i].box_name + "</option>")
                }
            }
            form.render();
        }
    });
}

function deleteRule(id) {
    $.ajax({
        url: 'email/deleteEmailRules',
        type: 'GET',
        contentType: "application/json; charset=utf-8",
        data: {
            "rid": id
        },
        success: function (date) {
            if (date.data == "success") {
                layer.msg("删除成功")
                $("#EmailRules").find("li").remove();
                showEmailRules();
            }
        }
    });
}

function addRule() {
    var EmailRules = {
        "rule_id": rulesid,
        "user_code": -1,
        "rule_name": $("#rule_name").val(),
        "rule_context": $("#rule_context").val(),
        "box_id": $("#userBox option:selected").val(),
        "acc_id": -1,
    }
    $.ajax({
        url: 'email/saveEmailRules',
        type: 'POST',
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify(EmailRules),
        success: function (date) {
            if (date.data == "success") {
                layer.msg("保存成功")
                $("#EmailRules").find("li").remove();
                showEmailRules();
            } else {
                layer.msg("保存失败")
            }

        }
    });
}